<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>博客详情页</title>
    <link rel="stylesheet" href="css/common.css">
    <link rel="stylesheet" href="css/blog_detail.css">
    <link rel="stylesheet" href="blog_list.html">
    <link rel="stylesheet" href="editor.md/css/editormd.min.css">

</head>
<body>
     <div class="nav">
        <img src="image/logo.jpg" alt="">
        <span>我的博客系统</span>
        <div class="spacer"></div>
        <a href="blog_list.html"> 主页</a>
        <a href="blog_edit.html">写博客</a>
        <a href="logout">注销</a>
   </div> 
   <div class="container">
    <!-- 左侧信息 -->
    <div class="container-left">
        <!-- 使用这个 .card 表示用户信息 -->
        <div class="card">
            <!-- 用户头像 -->
            <img src="image/国恩哥.jpg" alt="">
            <!-- 用户名 -->
            <h3>钊</h3>
            <a href="https://gitee.com/zhao-55" target="_blank">github 地址</a>
            <div class="counter">
                <span>文章</span>
                <span>分类</span>
            </div>
            <div class="counter">
                <span>1</span>
                <span>2</span>
            </div>
        </div>
    </div>
    <!-- 右侧信息 -->
    <div class="container-right">
        <!-- 博客标题 -->
        <h3 class="title"></h3>
        <!-- 博客发布时间 -->
        <div class="date"></div>
        <!-- 博客正文 -->
        <div id="content">
            
        </div>
    </div>
</div>
<script src="js/jquery.min.js"></script>
<script src="editor.md/lib/marked.min.js"></script>
<script src="editor.md/lib/prettify.min.js"></script>
<script src="editor.md/editormd.js"></script>
<script>
    $.ajax({
        type:'get',
        url:'blog' + location.search,
        success:function(body){
            let titleDiv = document.querySelector('.container-right .title');
            titleDiv.innerHTML = body.title;
            let dateDiv = document.querySelector('.date');
            dateDiv.innerHTML = body.postTime;
            editormd.markdownToHTML('content',{markdown : body.content});
        }
    })

    function checkLogin(){
                $.ajax({
                   type:'get',
                   url:'login',
                   success:function(body){
                    if(body.userId && body.userId > 0){
                        console.log("当前用户已经登录!");
                    }else{
                        location.assign('login.html');
                    }
                   }
                });
            }
            checkLogin();
            function getAuthor(){
                $.ajax({
                    type: 'get',
                    url:'author'+location.search,
                    success:function(body){
                        let h3 = document.querySelector('.container-left .card h3');
                        h3.innerHTML = body.username;
                    }
                });
            }
            getAuthor();
</script>

</body>
</html>